package com.gbei.center.utils.message;

public enum ResponseInfo {
	
	SUCCESS(0,"操作成功",true),
	SUCCESS_NOT_FOUND(200,"数据为空",true),
	INVALID_AUTHORIZATION(1,"invalid_authorization -- 用户未授权登录",true),
	INVALID_REQUEST(101,"invalid_request -- 请求缺少某个必需参数，包含一个不支持的参数或参数值，或者格式不正确",false),
	INVALID_CLIENT(102,"invalid_client -- 请求的client_id或client_secret参数无效。",false),
	INVALID_GRANT(103,"invalid_grant -- 请求的Authorization Code、Access Token、Refresh Token等信息是无效的",false),
	UNSUPPORTED_GRANT_TYPE(104,"unsupported_grant_type -- 不支持的grant_type",false),
	LACK_API_SCOPE(105,"lack_api_scope -- 应用缺少该接口的权限",false),
	LACK_ACTION_SCOPE(106,"lack_action_scope -- 应用缺少该接口的操作权限",false),
	EXPIRED_TOKEN(107,"expired_token -- 请求的Access Token已过期",false),
	LACK_TOKEN(108,"lack_token -- 请求缺少Access Token",false),
	INVALID_TOKEN(110,"invalid_token -- 请求的token不存在用户信息",false),
	FAILURE(-1,"操作失败",false);


	private int code;
	private String message;
	private boolean success;
	
	 ResponseInfo(int code, String message, boolean success){
		this.code = code;
		this.message = message;
		this.success = success;
	}

	public int getCode() {
		return code;
	}

	public String getMessage(){
		return this.message;
	}
	public boolean getSuccess(){
		return this.success;
	}
	
	public void setCode(int code) {
		this.code = code;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public void setSuccess(boolean success) {
		this.success = success;
	}
	
	public <T> Result<T> messageToResult(){
		Result<T> result = new Result<T>();
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		return result;
	}
	public <T> Result<?> messageToResult(Long time){
		Result<T> result = new Result<T>();
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		result.setVersion(time);
		return result;
	}
	
	public <T> Result<T> messageToResult(T obj){
		Result<T> result = new Result<T>();
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		result.setData(obj);
		return result;
	}
	
	public <T> Result<T> messageToResult(T obj,Long time){
		Result<T> result = new Result<T>();
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		result.setData(obj);
		result.setVersion(time);
		return result;
	}
	
	public Result<?> messageToResult(Result<?> result){
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		return result;
	}

	public Result<?> messageToResult(Result<?> result,Long time){
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		result.setVersion(time);
		return result;
	}

	public Result toResult(String message){
		Result result = new Result();
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage() + " -- " + message);
		return result;
	}
	
}
